﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfApplication1.Class.Bean;

namespace WpfApplication1
{
    /// <summary>
    /// Logique d'interaction pour Window1.xaml
    /// </summary>
    public partial class AddBugWindow : Window
    {
        private ListView list;

        public AddBugWindow(ListView list)
        {
            InitializeComponent();

            this.list = list;

            this.TypeBug.Items.Add(ClassBug.TYPE_DEMANDE_CORRECTION);
            this.TypeBug.Items.Add(ClassBug.TYPE_DEMANDE_EVOLUTION);
            this.TypeBug.Items.Add(ClassBug.TYPE_DEVELOPPEMENT);

            this.PrioriteBug.Items.Add(ClassBug.PRIORITE_BASSE);
            this.PrioriteBug.Items.Add(ClassBug.PRIORITE_MOY);
            this.PrioriteBug.Items.Add(ClassBug.PRIORITE_HAUTE);

            List<SearchField> listSF = new List<SearchField>();
            List<ClassProjet> listProjet = ClassProjet.Search(listSF);
            foreach (ClassProjet proj in listProjet)  
                this.ProjetBug.Items.Add(proj.NomProjet);

        }


        private void ValidBug(object sender, RoutedEventArgs e)
        {
            List<SearchField> list = new List<SearchField>();
            list.Add(new SearchField("NomProjet", this.ProjetBug.Text, SearchField.EGAL_A));

            List<ClassProjet> listProjet = ClassProjet.Search(list);
            ClassProjet projet = listProjet.First();


            ClassBug bug = new ClassBug();

            bug.Nom = this.NomBug.Text;
            bug.IdEmmeteur = ClassCurrentUserSingleton.Instance.Id;
            bug.IdProjet = projet.Id;
            bug.IdResponsable = projet.IdChefProj;
            bug.Priorite = this.PrioriteBug.Text;
            bug.Type = this.TypeBug.Text;

            if (this.EnvBug.Text == "")
                bug.Environnement = "Aucun";
            else
                bug.Environnement = this.EnvBug.Text;

            ClassBug.SaveOrUpdate(bug);

            List<SearchField> listSF = new List<SearchField>();
            List<ClassBug> listBug = ClassBug.Search(listSF);

            Binding bind = new Binding();
            bind.Source = listBug;
            this.list.DisplayMemberPath = "Nom";
            this.list.SetBinding(DataContextProperty, bind);
            
            MessageBox.Show("Bug signalé !");
            this.Close();


        }

       
                    
        }
    }

